import json

from py_xcp_bridge.common.datatypes import *

CHARACTERISTIC_DEPOSIT_MAP = {
    XCPRecordLayout.Scalar_BOOLEAN: "Scalar_BOOLEAN",
    XCPRecordLayout.Scalar_UBYTE: "Scalar_UBYTE",
    XCPRecordLayout.Scalar_SBYTE: "Scalar_SBYTE",
    XCPRecordLayout.Scalar_UWORD: "Scalar_UWORD",
    XCPRecordLayout.Scalar_SWORD: "Scalar_SWORD",
    XCPRecordLayout.Scalar_ULONG: "Scalar_ULONG",
    XCPRecordLayout.Scalar_SLONG: "Scalar_SLONG",
    XCPRecordLayout.Scalar_A_UINT64: "Scalar_A_UINT64",
    XCPRecordLayout.Scalar_A_INT64: "Scalar_A_INT64",
    XCPRecordLayout.Scalar_FLOAT32_IEEE: "Scalar_FLOAT32_IEEE",
    # XCPRecordLayout.Scalar_FLOAT64_IEEE: "Scalar_FLOAT64_IEEE",
}


path = "test/example_xcp.json"


a2l_d = json.load(open(path))

recoder_layout = a2l_d["PROJECT"]["MODULE"][0]["RECORD_LAYOUT"]

out_recoder_layout = []

for i, record in enumerate(recoder_layout):
    # print(f"Record {i}:")
    if (record["Name"]["Value"] in CHARACTERISTIC_DEPOSIT_MAP.values()):
        out_recoder_layout.append(record)
        
# 写到文件中
with open("test/used_recoder_layout.json", "w") as f:
    json.dump(out_recoder_layout, f, indent=2)

